﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using ODS.WebService.DeviceCommand;
using ODS.Utils;
using ODS.Model;
using ODS.WebService.DeviceData;
using ODS.Config;

namespace ODS.UserControls
{
    public partial class BlastPage : UserControl
    {
        public DetailDevicePage ParentView;

        public BlastPage()
        {
            InitializeComponent();
        }



        private async void btn_blast_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            btn_blast.IsEnabled = false;

            String errorMessage = null;

            InfoResult result_requestCommand = await RequestCommandService.RequestCommand(App.currentDeviceModel.DeviceIMEI, 12, null);

            if (result_requestCommand.IsSuccess )
            {
                String message = result_requestCommand.ReturnedObject as String;
                if (message == Constants.SUCCESS)
                {
                    ParentView.showChooseLocation();
                    //InfoResult result_getLastestMessage = await RetrieveDeviceLatestMessageService.RetrieveDeviceLatestMessage(App.currentDeviceModel.DeviceIMEI);
                    //if (result_getLastestMessage.IsSuccess)
                    //{
                    //    if (result_getLastestMessage.ReturnedObject != null)
                    //    {
                    //        MessageModel lastestMessage = result_getLastestMessage.ReturnedObject as MessageModel;

                            
                    //    }
                    //}
                    //else
                    //{
                    //    errorMessage = result_getLastestMessage.Error;
                        
                    //}
                }
                else
                {
                    errorMessage = "Request processing error. Please try again!";
                }
            }
            else
            {
                errorMessage = result_requestCommand.Error;
            }

            if (errorMessage != null)
            {
                MessageBox.Show(errorMessage, "Warning", MessageBoxButton.OK);
            }

            btn_blast.IsEnabled = true;
        }
    }
}
